#include <QMessageBox>
#include "pageresult.h"
#include <QFile>

resultPage::resultPage(QWidget *parent)
    : QWidget(parent)
{
    setFixedSize(1015,768);

    setStyleSheet(".QLineEdit{min-height:30px;}"
                  ".QLineEdit{min-width:250px;}");

    QFont ft;
    ft.setPointSize(10);
    ft.setBold(true);
    QPalette pe;
    pe.setColor(QPalette::WindowText,Qt::white);

    //序号
    QLabel *labXuhao=new QLabel(tr("序号"));
    labXuhao->setPalette(pe);

    labRecordIndex=new QLineEdit("");
    labRecordIndex->setFont(ft);
    labRecordIndex->setFixedWidth(200);
    labRecordIndex->setReadOnly(true);

    QHBoxLayout *HlayXuhao = new QHBoxLayout;
    HlayXuhao->addWidget(labXuhao);
    HlayXuhao->addWidget(labRecordIndex);
    HlayXuhao->addStretch(1);

    //同步方式
    QLabel *labTbfs=new QLabel(tr("同步方式"));
    labTbfs->setPalette(pe);

    labRecordSyncMethod=new QLineEdit("");
    labRecordSyncMethod->setFont(ft);
    labRecordSyncMethod->setFixedWidth(200);
    labRecordSyncMethod->setReadOnly(true);

    QHBoxLayout *HlayTbfs = new QHBoxLayout;
    HlayTbfs->addWidget(labTbfs);
    HlayTbfs->addWidget(labRecordSyncMethod);
    HlayTbfs->addStretch(1);

    //标准选择
    QLabel *labBzxz=new QLabel(tr("标准一次"));
    labBzxz->setPalette(pe);

    labRecordStdValue=new QLineEdit("");
    labRecordStdValue->setFont(ft);
    labRecordStdValue->setFixedWidth(200);
    labRecordStdValue->setReadOnly(true);

    QHBoxLayout *HlayBzxz = new QHBoxLayout;
    HlayBzxz->addWidget(labBzxz);
    HlayBzxz->addWidget(labRecordStdValue);
    HlayBzxz->addStretch(1);

    //被测选择
    QLabel *labBcxz=new QLabel(tr("标准二次"));
    labBcxz->setPalette(pe);

    labRecordStdInput=new QLineEdit("");
    labRecordStdInput->setFont(ft);
    labRecordStdInput->setFixedWidth(200);
    labRecordStdInput->setReadOnly(true);

    QHBoxLayout *HlayBcxz = new QHBoxLayout;
    HlayBcxz->addWidget(labBcxz);
    HlayBcxz->addWidget(labRecordStdInput);
    HlayBcxz->addStretch(1);

    //测试时间
    QLabel *labDate=new QLabel(tr("测试时间"));
    labDate->setPalette(pe);
    labDate->setFont(ft);
    labDate->setMinimumWidth(96);

    labRecordDate=new QLineEdit("");
    labRecordDate->setFont(ft);
    labRecordDate->setFixedWidth(200);
    labRecordDate->setReadOnly(true);

    QHBoxLayout *HlayDate = new QHBoxLayout;
    HlayDate->addWidget(labDate);
    HlayDate->addWidget(labRecordDate);
    HlayDate->addStretch(1);

    //额定一次电流
    QLabel *labEDYC=new QLabel(tr("被测输入"));
    labEDYC->setPalette(pe);

    labRecordDut=new QLineEdit("");
    labRecordDut->setFont(ft);
    labRecordDut->setFixedWidth(200);
    labRecordDut->setReadOnly(true);

    labYcDw=new QLabel(tr(""));
    labYcDw->setPalette(pe);

    QHBoxLayout *HlayEDYC = new QHBoxLayout;
    HlayEDYC->addWidget(labEDYC);
    HlayEDYC->addWidget(labRecordDut);
    HlayEDYC->addWidget(labYcDw);
    HlayEDYC->addStretch(1);

    //---显示布局
    QGridLayout *GlayParaShow = new QGridLayout;
    GlayParaShow->addLayout(HlayXuhao,0,0,1,1);
    GlayParaShow->addLayout(HlayTbfs,1,0,1,1);
    GlayParaShow->addLayout(HlayDate,2,0,1,1);
    GlayParaShow->addLayout(HlayBzxz,0,1,1,1);
    GlayParaShow->addLayout(HlayBcxz,1,1,1,1);
    GlayParaShow->addLayout(HlayEDYC,2,1,1,1);

    labDataCount=new QLabel("");

 //   labXuhao->setStyleSheet("color:rgb(255,255,255);");
    labXuhao->setFont(ft);
    labXuhao->setMinimumWidth(96);
 //   labTbfs->setStyleSheet("color:rgb(255,255,255);");
    labTbfs->setFont(ft);
    labTbfs->setMinimumWidth(96);
 //   labBzxz->setStyleSheet("color:rgb(255,255,255);");
    labBzxz->setFont(ft);
    labBzxz->setMinimumWidth(96);
  //  labBcxz->setStyleSheet("color:rgb(255,255,255);");
    labBcxz->setFont(ft);
    labBcxz->setMinimumWidth(96);
 //   labYc->setStyleSheet("color:rgb(255,255,255);");
    labEDYC->setFont(ft);
    labEDYC->setMinimumWidth(96);
 //   labYcDw->setStyleSheet("color:rgb(255,255,255);");
    labYcDw->setFont(ft);
 //   labDataCount->setStyleSheet("color:rgb(255,255,255);");
    labDataCount->setFont(ft);
    labDataCount->setMinimumWidth(200);

 //   txtDate->setStyleSheet("color:rgb(250,155,50);");
    inittabWcData();
    btnFirst=new QPushButton("");
    btnFirst->setMinimumHeight(30);
    btnFirst->setMaximumWidth(30);
    btnFirst->setStyleSheet("background-image:url(:image/first.png);color:rgb(250,155,50);");
    btnPrevious=new QPushButton("");
    btnPrevious->setMinimumHeight(30);
    btnPrevious->setMaximumWidth(30);
    btnPrevious->setStyleSheet("background-image:url(:image/previous.png);color:rgb(250,155,50);");
    btnNext=new QPushButton("");
    btnNext->setMinimumHeight(30);
    btnNext->setMaximumWidth(30);
    btnNext->setStyleSheet("background-image:url(:image/next.png);color:rgb(250,155,50);");
    btnLast=new QPushButton("");
    btnLast->setMinimumHeight(30);
    btnLast->setMaximumWidth(30);
    btnLast->setStyleSheet("background-image:url(:image/last.png);color:rgb(250,155,50);");
    btnDel=new QPushButton("");
    btnDel->setMinimumHeight(30);
    btnDel->setMaximumWidth(30);
    btnDel->setStyleSheet("background-image:url(:image/del.png);color:rgb(250,155,50);");
    btnFind=new QPushButton("");
    btnFind->setMinimumHeight(30);
    btnFind->setMaximumWidth(30);
    btnFind->setStyleSheet("background-image:url(:image/find.png);color:rgb(250,155,50);");
    btnFind->hide();

//    ycLayout->addStretch(1);
    QHBoxLayout *btnLayout = new QHBoxLayout;
    btnLayout->addWidget(labDataCount);
    btnLayout->addWidget(btnFind);
    btnLayout->addWidget(btnFirst);
    btnLayout->addWidget(btnPrevious);
    btnLayout->addWidget(btnNext);
    btnLayout->addWidget(btnLast);
    btnLayout->addWidget(btnDel);

//    QHBoxLayout *vlayout = new QHBoxLayout;
//    vlayout->addLayout();
    QPushButton *btnBack = new QPushButton("返回");
    btnBack->setFixedSize(200,30);
    connect(btnBack, SIGNAL(clicked(bool)), this, SLOT(hide()));
    btnBack->hide();

    QVBoxLayout *VLayTop = new QVBoxLayout;
    VLayTop->addLayout(GlayParaShow);
    VLayTop->addSpacing(50);
    VLayTop->addWidget(tabWcData);
    VLayTop->setStretchFactor(GlayParaShow,1);
    VLayTop->setStretchFactor(tabWcData,2);

    QVBoxLayout *LayoutMain = new QVBoxLayout;
    LayoutMain->setContentsMargins(20,30,30,20);
//    mainLayout->addLayout(topLayout);
//    mainLayout->addLayout(bzLayout);
//    mainLayout->addLayout(ycLayout);
    LayoutMain->addLayout(VLayTop);
    LayoutMain->addSpacing(50);
//    mainLayout->addWidget(tabWc);
    LayoutMain->addLayout(btnLayout);
    LayoutMain->addWidget(btnBack);
    setLayout(LayoutMain);
}

void resultPage::inittabWcData()
{
    tabWcData=new QTableView();
    QFont ft;
    ft.setPixelSize(15);
    ft.setBold(true);

    tabWcData->setMinimumWidth(700);
    tabWcData->setAlternatingRowColors(true);

    tabWcData->setEditTriggers(QTableView::NoEditTriggers);//设置非编辑状态
    tabWcData->setSelectionBehavior(QTableView::SelectRows);//设置点击行为行
    tabWcData->setDragEnabled(false);

    model = new QStandardItemModel();
    model->setColumnCount(6);
    model->setHeaderData(0,Qt::Horizontal,tr("对象"));
    model->setHeaderData(1,Qt::Horizontal,tr("百分点"));
    model->setHeaderData(2,Qt::Horizontal,tr("标准有效值"));
    model->setHeaderData(3,Qt::Horizontal,tr("被测有效值"));
    model->setHeaderData(4,Qt::Horizontal,tr("比差"));
    model->setHeaderData(5,Qt::Horizontal,tr("角差"));

    QStringList list;
    list << "Ua" << "Ub" << "Uc"<<"Ia"<<"Ib"<<"Ic";
    model->setVerticalHeaderLabels(list);

    tabWcData->verticalHeader()->hide();
    tabWcData->setModel(model);
    tabWcData->setColumnWidth(0,202);
    tabWcData->setColumnWidth(1,100);
    tabWcData->setColumnWidth(2,160);
    tabWcData->setColumnWidth(3,160);
    tabWcData->setColumnWidth(4,170);
    tabWcData->setColumnWidth(5,170);
}
